package com.note.back.mapper;

import com.note.back.pojo.Note;
import org.apache.ibatis.annotations.*;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface NoteMapper {
    //新增
    @Insert("insert into note(name,description,author,category,create_time,update_time)" +
            "values(#{name},#{description},#{author},#{category},#{createTime},#{updateTime})")
    void add(Note note);

    //列表
    @Select("select * from note where author=#{author}")
    List<Note> list(Integer author);

    //更新
    @Update("update note set name=#{name},description=#{description},category=#{category},update_time=#{updateTime} where id=#{id}")
    void update(Note note);

    //查找
    @Select("select * from note where id=#{id}")
    Note findById(Integer id);

    //删除
    @Delete("delete from note where id=#{id}")
    void delete(Integer id);

    @Select("select * from note where author=#{author} and name LIKE CONCAT('%', #{title}, '%')")
    List<Note> searchTitle(String title, Integer author);

    @Select("select * from note where author=#{author} and category=#{categoryId}")
    List<Note> searchCategory(Integer categoryId, Integer author);
    @Select("select * from note where author = #{author} and create_time BETWEEN #{start} AND #{end}")
    List<Note> searchCreateTime(LocalDateTime start, LocalDateTime end, Integer author);
    @Select("select * from note where author = #{author} and update_time BETWEEN #{start} AND #{end}")
    List<Note> searchUpdateTime(LocalDateTime start, LocalDateTime end, Integer author);
    @Update("update note set content_html=#{contentHtml},content_md=#{contentMd},update_time=#{updateTime} where id=#{id}")
    void save(Note note);
}
